package com.Setting.Bug.Controller;
import com.Setting.Bug.Entity.Bug;
import com.Setting.Bug.Service.BugService;
import com.utils.APIRespones;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin("*")
@RestController
public class BugController {

    @Autowired
    private BugService bugService;

    @PostMapping("/api/bugs/commit")
    public APIRespones commitBug(@RequestHeader("token") String token,
                                 @RequestParam(value = "files",required = false) MultipartFile[] files,
                                 @RequestParam("summary") String summary,
                                 @RequestParam("severity") String severity,
                                 @RequestParam("module") String module,
                                 @RequestParam("regression") String regression,
                                 @RequestParam("description") String description) {
        return bugService.commitBug(token, files, summary, severity, module, regression, description);
    }
    @GetMapping("api/bugs/list")
    public APIRespones getBugList() {
        List<Bug> bugs = bugService.getProcessedBugList();

        Map<String, Object> data = new HashMap<>();
        data.put("bugs", bugs);
        System.out.println(data);
        APIRespones apiRespones = APIRespones.success(data);
        return apiRespones;
    }



}
